package Models;

import java.rmi.RemoteException;
import java.util.LinkedList;

import listeners.CanMoveListenerBoard;

public class StandardBoardModel2D implements BoardModel2D{

	private ChessPieceModel[][] board = new ChessPieceModel[8][8];
	private LinkedList<CanMoveListenerBoard> canMoveListeners = new LinkedList<CanMoveListenerBoard>();
	
	@Override
	public ChessPieceModel[][] getBoard() {
		
		return board;
	}

	@Override
	public ChessPieceModel getPiece(Point2D position) {
		
		return board[position.getX()][position.getY()];
	}

	@Override
	public void setPiece(Point2D position, ChessPieceModel chessPiece) {
		board[position.getX()][position.getY()] = chessPiece;
		
	}

	@Override
	public void addCanMoveListener(CanMoveListenerBoard listener) {
		canMoveListeners.add(listener);
		
	}

	@Override
	public void removeCanMoveListener(CanMoveListenerBoard listener) {
		canMoveListeners.remove(listener);
		
	}

	@Override
	public boolean canMoveNotify(Point2D from, Point2D to, BoardModel2D board)
			throws RemoteException {
		
		for(CanMoveListenerBoard listener : canMoveListeners)
		{
			if(!listener.canMoveNotify(from, to, this))
				return false;
		}
			
		return true;
	}



}
